function atualizaCarrinho(drag){
	id = drag.id.substr(7);
	$('#compras').load('loja.adiciona.logic',{'musica.id':id});
	//alert(drag.id);
}
function remover(drag){
		id = this.id.substr(7);
		$('#compras').load('loja.remove.logic',{'musica.id':id});
}
$(function(){
	$('.musica').Draggable({
		ghosting: true,
		opacity: 0.7,
		zIndex: 10,
		revert: true 
	});
	$('#carrinho').Droppable({
		accept: 'musica',
		onDrop: atualizaCarrinho
	});
});

$(function(){
	$('.compra').Draggable({
		ghosting: true,
		opacity: 0.7,
		zIndex: 10,
		revert: true,
		onStop: remover
	});
});
function tocar(musica){
	alert(musica);
	parar_musica();
	var href = $('a',musica).attr('href');
	var caminho = "mp3/player.swf?autoplay=true&song_url=mp3/"+href;
	
	var flash = '<object type="application/x-shockwave-flash" '
	+ ' data="'+caminho+'" width="17" height="17">'
	+ ' <param name="movie" value="'+caminho+'" />'
	+ ' </object>';
	$("#player").append(flash);
}
function parar_musica(){
	$("#player object").remove();
}
$(function() {
	$('#player').Droppable({
		accept: 'musica',
		onDrop: tocar
	});
});

$(function() {
	$('#player').click(parar_musica);
});